#include "bsp_spi.h"

extern SPI_HandleTypeDef hspi1;

/* T(spi_baudate_16)=1M/(72M/16)=222.2ns,
 * Code(0)=1*T(VOH)+3*T(VOL)=1000b=0x8;
 * Code(1)=3*T(VOH)+1*T(VOL)=1110b=0xe;
 * GRB = 1*Byte(G)+1*Byte(R)+1*Byte(B);
 * T(ret) > 280us;
 * n*Pixels = n*GRB+1*T(ret); 
 * */
 
#define MAX_PIXEL_LENGTH 100

void GRB_Trans(uint8_t* GRB_value,uint8_t *buf)
{
	uint32_t tmp = 0x0;
	//G:R:B=0-255:0-255:0-255
	//color(bit8*4)=CODE(bit3)*8;
	//1pixel(bit8*12)=3*color(bit8*4);

	for(uint8_t i=0;i<3;i++)
	{
		tmp = 0x0;
		
		for(uint8_t j=0;j<8;j++)
		{
			if((GRB_value[i]<<j) & 0x80)
			{
				tmp |= 0xe;
			}else
			{
				tmp |= 0x8;
			}
			
			tmp <<= 4;
		}
		
		buf[i*4+0] = (uint8_t)tmp>>24;
		buf[i*4+1] = (uint8_t)tmp>>16;
		buf[i*4+2] = (uint8_t)tmp>>8;
		buf[i*4+3] = (uint8_t)tmp;
		
	}
	
}


void GRB_SameColor_Send(GRB_TypeDef *GRB_array,uint16_t pixel_cnt)
{
	
	
}
	
	
	
	
	
		


		
		
			
		
 

